package com.sxj.conmon.excel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;

import com.sxj.base.util.DateUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class myexcel {
	/**
	 * 读写excel
	 * @param args
	 */
	public static void main(String[] args) {
		File target=new File("F:\\1111.xlsx");
		try {
			InputStream in=new FileInputStream(target);
			List<Student> list = new ArrayList<Student>();
			ExcelUtil.importExcel(list, in, Student.class);
			log.info(list.toString());
			
			ExcelUtil.exportExcel(list, "F:\\111.xlsx", Student.class);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
	}
	
	@SuppressWarnings("deprecation")
	/**
	 * 读取文件数据
	 * @param response
	 */
	public void GetVersion(HttpServletResponse response) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("#97.time", DateUtil.getTimeInMillis(new Date()).toString());
		map.put("#98.time", DateUtil.getTimeInMillis(new Date()).toString());
		try {
			InputStream in = this.getClass().getResourceAsStream("/templates/version.json");
			String version = IOUtils.toString(in);
			for (String key : map.keySet()) {
				version = version.replaceAll(key, map.get(key));
			}
			//response.setContentType(ContentType.APPLICATION_JSON.getMimeType());
			IOUtils.write(version, response.getOutputStream());
			response.getOutputStream().flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

}
